package com.treasure.mall.zbqmallapi.config;

import com.treasure.mall.biz.service.core.user.UserService;
import com.treasure.mall.zbqmallapi.resolver.ClientArgumentResolver;
import com.treasure.mall.zbqmallapi.resolver.UserArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.zbqmallapi.config
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/6/12 09:38
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * Copyright 2019-2022 com.treasure.mall.zbqmallapi.config Inc. All rights reserved.
 */
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private UserService userService;

    /**
     * 配置接口返回格式
     *
     * @param converters
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));
        converters.add(converter);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(new UserArgumentResolver(userService));
        resolvers.add(new ClientArgumentResolver());
    }
}
